
package codeGenerate.common.utils;

import org.apache.commons.lang3.StringUtils;

public class SystemUtils {

	public static final String NAME_SPLIT = "_|-";

	/**
	 * @description: 根据代码路径生成默认实体类的名称
	 * @return
	 */
	public static String getBeanNameByPath(String path) {
		String[] split = path.split("\\.");
		String name = split[split.length - 1];
		return name.substring(0, 1).toUpperCase() + name.substring(1);
	}

	/**
	 * @description: 获取模板默认的路径
	 * @return
	 */
	public static String defalutTemplateDirectory() {
		return SystemUtils.class.getResource("/").getPath() + "template";
	}

	/**
	 * @description: 大写第一个字母
	 * @return
	 */
	public static String upperFirst(String str) {
		return str.substring(0, 1).toUpperCase() + str.substring(1);
	}

	/**
	 * @description: 将名字变为类名,如有下划线，自动去除，首字母变大写
	 * @creator: dw-fu1
	 * @createDate: 2021年4月29日 
	 * @param name
	 * @return
	 */
	public static String toClassName(String name) {
		String[] names = name.split(NAME_SPLIT);
		if (names.length == 1) {
			String className = names[0];
			return className.substring(0, 1).toUpperCase() + className.substring(1);
		}
		StringBuffer sb = new StringBuffer();
		sb.append(names[0].toLowerCase());
		for (int i = 1; i < names.length; i++) {
			if (StringUtils.isNotBlank(names[i])) {
				sb.append(names[i].substring(0, 1).toUpperCase());
				sb.append(names[i].substring(1).toLowerCase());
			}
		}
		return sb.substring(0, 1).toUpperCase() + sb.substring(1);
	}

	public static String toClassFieldName(String name) {
		String[] names = name.split(NAME_SPLIT);
		if (names.length == 1) {
			String fieldName = names[0];
			return fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1);
		}
		StringBuffer sb = new StringBuffer();
		sb.append(names[0].toLowerCase());
		for (int i = 1; i < names.length; i++) {
			if (StringUtils.isNotBlank(names[i])) {
				sb.append(names[i].substring(0, 1).toUpperCase());
				sb.append(names[i].substring(1).toLowerCase());
			}
		}
		return sb.substring(0, 1).toLowerCase() + sb.substring(1);
	}

	public static void main(String[] args) {
		System.out.println(toClassName("resultMessage"));
	}
}
